package com.freshman_registration.util;

import lombok.Data;

import java.io.Serializable;
@Data
//封装统一返回结果类
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer code;//200成功,非200失败
    private String message;//返回消息
    private T data;//返回数据

    public Result() {
    }
    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
//    请求成功方法
    public static <T> Result<T> success() {
        return new Result<T>(200, "操作成功");
    }
    public static <T> Result<T> success(T data) {
        return new Result<T>(200, "操作成功", data);
    }
    public static <T> Result<T> success(String message, T data) {
        return new Result<T>(200, message, data);
    }
//请求失败方法
    public static <T> Result<T> fail(Integer code, String message) {
        return new Result<T>(code, message);
    }
    public static <T> Result<T>
    fail(String message) {
        return new Result<T>(500, message);
    }
}
